class Member:
    def __init__(self, level):
        # 定义不同会员等级对应的折扣率
        self._discount_rates = {
            "普通会员": 0.95,
            "银卡会员": 0.9,
            "金卡会员": 0.85
        }
        self.level = level

    @property
    def discount_rate(self):
        # 根据会员等级获取对应的折扣率
        return self._discount_rates.get(self.level, 1)


class CartItem:
    def __init__(self, name, price, quantity, member=None):
        self.name = name
        self.price = price
        self.quantity = quantity
        self.member = member

    @property
    def total_price(self):
        # 计算商品总价
        if self.member:
            return self.price * self.quantity * self.member.discount_rate
        return self.price * self.quantity


class ShoppingCart:
    def __init__(self):
        self.items = []

    def add_item(self, item):
        # 向购物车添加商品
        self.items.append(item)

    def apply_discount(self):
        # 计算折扣后的总价
        return sum(item.total_price for item in self.items)

    def show(self):
        print("购物车内容：")
        for item in self.items:
            original_price = item.price * item.quantity
            if item.member:
                discount = original_price - item.total_price
                print(
                    f"{item.name}: 原价 {original_price} 元，会员等级：{item.member.level}，折扣 {discount} 元，实付 {item.total_price} 元")
            else:
                print(f"{item.name}: 总价 {original_price} 元")
        total = self.apply_discount()
        print(f"折扣后总价: {total} 元")


# 测试代码
if __name__ == "__main__":
    # 创建不同等级的会员
    normal_member = Member("普通会员")
    silver_member = Member("银卡会员")
    gold_member = Member("金卡会员")

    # 创建购物车
    cart = ShoppingCart()
    # 添加商品到购物车，部分商品有会员，部分无会员
    cart.add_item(CartItem("苹果", 5, 3))
    cart.add_item(CartItem("香蕉", 3, 2, normal_member))
    cart.add_item(CartItem("牛奶", 8, 1, silver_member))
    cart.add_item(CartItem("面包", 6, 2, gold_member))

    # 显示购物车信息
    cart.show()
